package MapAndSet;

public class HashBuck2 <K,V>{
    static  class  Node<K,V>{
        public K key;
        public V val;
        public Node<K,V> next;

        public Node(K key, V val) {
            this.key = key;
            this.val = val;
        }
    }
    public Node<K,V>[] table=(Node<K, V>[])new Node[10];
    public int usedSize;
    public static  final double DEFAULT_LOAD_FACTOR = 0.75F;
    public void put(K key,V val){
        int hashcode = key.hashCode();
        int index = hashcode%table.length;
        Node<K,V> cur =table[index];
        while (cur !=null){
            if (cur.key==key){
                cur.val = val;
            }
            cur =cur.next;
        }
        Node<K,V> node =new Node<>(key,val);
        node.next = table[index];
        table[index] = node;
        usedSize++;
    }
    public V getVal(K key){
        int hashcode = key.hashCode();
        int index = hashcode%table.length;
        Node <K,V> node = table[index];
        while (node !=null){
            if (node.key==key){
                return node.val;
            }
            node = node.next;
        }
        return null;
    }
}
